package com.beijiteshop.shop.app

import android.app.Application
import android.content.Context
import com.alibaba.android.arouter.launcher.ARouter
import com.beijiteshop.libcommon.login.UserInfoUtil
import com.beijiteshop.libcommon.pagestate.LoadSirHelper
import com.beijiteshop.shop.ui.address.addressModule
import com.beijiteshop.shop.ui.category.categoryModule
import com.beijiteshop.shop.ui.coupon.couponModule
import com.beijiteshop.shop.ui.detail.detailModule
import com.beijiteshop.shop.ui.home.homeModule
import com.beijiteshop.shop.ui.login.loginMoudle
import com.beijiteshop.shop.ui.notification.notificationModule
import com.beijiteshop.shop.ui.order.orderModule
import com.beijiteshop.shop.ui.search.searchModule
import com.beijiteshop.shop.ui.shopcar.shopCarModule
import com.beijiteshop.shop.wxapi.WXHelper
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
import org.koin.core.module.Module
import kotlin.properties.Delegates

/**
 * @Author LiaoZhongKai
 * @Date 2021/3/1 16:36
 * @Description
 */
class ShopApplication : Application() {

    companion object{

        var shopApplication: ShopApplication by Delegates.notNull()
    }

    private val moduleList = arrayListOf<Module>(
        homeModule,
        detailModule,
        orderModule,
        addressModule,
        categoryModule,
        loginMoudle,
        notificationModule,
        searchModule,
        couponModule,
        shopCarModule
    )

    override fun onCreate() {
        super.onCreate()
        shopApplication = this
        //Koin
        startKoin {
            androidContext(this@ShopApplication)
            modules(moduleList)
        }

        UserInfoUtil.init(this)
        LoadSirHelper.build()

        //Arouter
        ARouter.init(this)

        WXHelper.getInstance().register(this)
    }

    fun getContext(): Context{
        return shopApplication.applicationContext
    }
}